<template>
    <div class="template">
      <!-- Tree筛选 -->
        <div id="CategoryTree" style="width: 180px">
            <el-input
                @clear="officeTaskAlreadyHandleClear"
                placeholder="输入关键字进行过滤"
                clearable
                v-model="filterText">
            </el-input>
            <el-tree
                class="filter-tree"
                :data="dataCategory"
                :props="defaultCategoryProps"
                default-expand-all
                :filter-node-method="filterCategoryNode"
                ref="tree"
                show-checkbox
                node-key="categoryId"
                :check-strictly="true"
                @check-change="handleCheckChange"
                @node-click="nodeClick">
                <!-- 处理菜单内容过长 -->
                <span class="custom-tree-node" slot-scope="{ node }">
                    <el-tooltip class="item" effect="dark" :content="node.label" placement="top-start">
                        <span > {{ node.label | ellipsis(8) }} </span>
                    </el-tooltip>
                </span>
            </el-tree>
          </div>
          <div id="pageList" style="margin-left: 20px;">
            <div class="addActBtCategory">
                <div style="float: left;display: flex;">
                    <el-input
                            @clear="officeTaskAlreadyHandleClear"
                            clearable
                            style="margin-right: 8px;"
                            class="officeTaskAlreadyHandleClear"
                            prefix-icon="el-icon-search"
                            placeholder="请输入流程定义名称"
                            v-model="page.processDefinitionName"
                            @keydown.enter.native="initOfficeTaskAlreadyHandleQuery">
                    </el-input>
                    <el-input
                            @clear="officeTaskAlreadyHandleClear"
                            clearable
                            style="margin-right: 8px;"
                            class="officeTaskAlreadyHandleClear"
                            prefix-icon="el-icon-search"
                            placeholder="请输入流程任务名称"
                            v-model="page.taskName"
                            @keydown.enter.native="initOfficeTaskAlreadyHandleQuery">
                    </el-input>
                    <el-button style="margin-left: 8px;" icon="el-icon-search" type="info" @click="initOfficeTaskAlreadyHandleQuery">查询</el-button>
                </div>

                <div style="display: flex;justify-content: flex-end">
                    <el-button
                            type="primary"
                            @click="resetCondition"><i class="el-icon-remove"></i><span>重置</span>
                    </el-button>
                </div>
            </div>
            <!-- 列表 -->
            <div>
            <el-table
                    :data="OfficeTaskAlreadyHandleList"
                    stripe
                    border
                    v-loading="loading"
                    element-loading-text="正在加载..."
                    element-loading-spinner="el-icon-loading"
                    element-loading-background="rgba(0, 0, 0, 0.8)">
                <el-table-column
                        label="类别名称"
                        width="150">
                    <template slot-scope="scope">
                        <span>{{ scope.row.categoryName }}</span>
                    </template>
                </el-table-column>
                <el-table-column
                        label="实例名称"
                        width="150">
                    <template slot-scope="scope">
                        <span>{{ scope.row.processInstanceName }}</span>
                    </template>
                </el-table-column>
                <el-table-column
                        label="流程名称"
                        width="150">
                    <template slot-scope="scope">
                        <span>{{ scope.row.processDefinitionName }}</span>
                    </template>
                </el-table-column>
                <el-table-column
                        label="任务名称"
                        width="150">
                    <template slot-scope="scope">
                        <span>{{ scope.row.taskName }}</span>
                    </template>
                </el-table-column>
                <el-table-column
                        label="签收者"
                        width="150">
                    <template slot-scope="scope">
                        <span>{{ scope.row.assignee }}</span>
                    </template>
                </el-table-column>
                <el-table-column
                        label="开始时间" width="150">
                    <template slot-scope="scope">
                        <span>{{scope.row.startTime| dateFormat('YYYY-MM-DD HH:mm:ss')}}</span>
                    </template>
                </el-table-column>
                <el-table-column
                        label="结束时间" width="150">
                    <template slot-scope="scope">
                        <span v-if="scope.row.endTime!=null">{{scope.row.endTime| dateFormat('YYYY-MM-DD HH:mm:ss')}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button
                                type="text"
                                title="通过流程实例编号获取审批信息"
                                @click="TaskCommentByProcessInstanceId(scope.row)"><i class="el-icon-view"></i>详情</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div style="display: flex;justify-content: flex-end;margin-top: 8px;">
                <el-pagination
                        background
                        @current-change="currentChange"
                        @size-change="sizeChange"
                        layout="sizes, prev, pager, next, jumper, ->, total, slot"
                        :total="total">
                </el-pagination>
            </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name:"officeTaskAlreadyHandle",
    data(){
        return{
            filterText: '',
            // 查询目录属性设置
            defaultCategoryProps:{
                children: 'children',
                label: 'categoryName'
            },
            // 初始化目录
            dataCategory:[],
            loading: false,
            page:{
              processDefinitionName:'',
              taskName:'',
              deploymentCategory:'',
              pageNum:1,
              pageSzie:10
            },
            OfficeTaskAlreadyHandleList:[],
            multipleSelection:[],
            total:0
        }
    },
    mounted(){
        // 初始化模型类别列表
        this.initOfficeTaskAlreadyHandleQuery();
        this.ProcessModelCategoryTreeSelects();
    },
    methods:{
        officeTaskAlreadyHandleClear(){
          this.resetCondition();
        },
        // 详情
        TaskCommentByProcessInstanceId(data){
           this.$router.push({
               path: '/TaskComment',
               // 参数传递
               query: {
                   processInstanceId:data.processInstanceId,
                   viewPage:'officeTaskAlreadyHandle'
               }
           })
        },
       // 重置查询条件
        resetCondition(){
            this.$refs.tree.setCheckedNodes([]);
            this.filterText = '';
            this.page.deploymentCategory = '';
            this.page.taskName = '';
            this.page.processDefinitionName = '';
            this.initOfficeTaskAlreadyHandleQuery();
        },
      // 菜单目录选择
        handleCheckChange(data, checked, node){
            if(checked == true){
                this.filterText = data.categoryName;
                this.page.deploymentCategory = data.categoryId;
                this.$refs.tree.setCheckedNodes([data]);
            }
        },
        nodeClick(data,checked,node){
            this.filterText = data.categoryName;
            this.page.deploymentCategory = data.categoryId;
            this.$refs.tree.setCheckedNodes([data]);
        },
        // 目录节点过滤
        filterCategoryNode(value,dataCategory){
            if (!value) return true;
            return dataCategory.categoryName.indexOf(value) !== -1;
        },
        // 获取目录
        ProcessModelCategoryTreeSelects(){
            this.getRequest("/activity/ActBtCategory/query/ProcessModelCategoryTree").then(resp => {
                if (resp) {
                    this.dataCategory = resp.data;
                }
            });
        },
        initOfficeTaskAlreadyHandleQuery(){
            this.loading = true;
            this.postRequest("/activity/TaskAlreadyHandle/query/TaskAlreadyHandlePageList",this.page).then(resp => {
                this.loading = false;
                if (resp) {
                    this.OfficeTaskAlreadyHandleList = resp.data.list;
                    this.total = resp.data.total;
                }
            });
        },
        // 分页
        sizeChange(currentSize) {
            this.page.pageSize = currentSize;
            this.initOfficeTaskAlreadyHandleQuery();
        },
        currentChange(currentPage) {
            this.page.pageNum = currentPage;
            this.initOfficeTaskAlreadyHandleQuery();
        },
    }
}
</script>

<style>
    .officeTaskAlreadyHandleClear{
        width: 300px;margin-right: 8px;
    }
    .addActBtCategory{
        margin-bottom: 10px;
    }

    #CategoryTree{
        width: 180px;
        border: 1px solid #E7E7E7;
        height: 730px;
    }

    .filter-tree{
        overflow: auto;
        flex: 1;
        width: 170px;
        height: 600px;
        margin:  10px;
    }

     #CategoryTree #pageList{
        display: flex;
        justify-content: flex-end;
        flex: 1;
    }
    .template{
        display: flex;
    }
</style>
